<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <cpn></cpn>
        <cpn></cpn>
        <cpn ref="aaa"></cpn>
        <button @click="btnClick">按钮$children,访问子组件</button>
        <button @click="btnClick2">$ref访问子组件</button>
    </div>





    <template id="CPN">
        <div>
            <h2>我是子组件</h2>
        </div>
    </template>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                message: '我是你爹!'
            },
            methods: {
                btnClick() {
                    console.log(this.$children);
                    this.$children[0].showMessage();
                    for (let c of this.$children) {
                        c.showMessage();
                    }
                },
                btnClick2() {
                    console.log(this.$refs);
                    console.log(this.$refs.aaa.name);
                }
            },
            components: {
                cpn: {
                    template: '#CPN',
                    data() {
                        return {
                            name: "我是子组件的name属性"
                        }
                    },
                    methods: {
                        showMessage() {
                            console.log('我是子组件：：：');
                        }
                    },
                }
            }
        });
    </script>
</body>

</html>